home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.hut.fi!nntp!hakola
- From: hakola@cadmail.hut.fi (Petri Hakola)
- Newsgroups: comp.lang.c
- Subject: Splitting String ?
- Date: 12 Jan 1996 13:11:28 GMT
- Organization: Capten Napalm`s Thermonuclear League of Liberty
- Distribution: world
- Message-ID: <HAKOLA.96Jan12151128@jung.hut.fi>
- Reply-To: Petri.Hakola@hut.fi
- NNTP-Posting-Host: jung.hut.fi
-
-
- Have I missed something (again:) or why doesn't this code
- work? I should split dos-a-like-filename and add new postfix
- instead of old one (i.e. DATA.TXT --> DATA.UPD It seems to
- work correctly if the filename has an old postfix, but if
- there isn't one start won't return what it should.
-
- - P -
-
-
- ---Clip---
- #include <stdio.h>
- #include <string.h>
-
- char *newname(char *s) {
-
- char *dot;
- char *start;
- char end[5];
-
- strcpy(end,".UPD");
- start = s;
- dot = strchr(s,'.');
- if( dot == NULL) {
- start[strlen(start)] = '\0';
- dot = end;
- } else {
- *dot = '\0';
- dot++;
- dot = end;
- }
- strcat(start, dot);
- return start;
- }
-
- main() {
- printf("%s\n",newname("LONGNAME.TXT"));
- printf("%s\n",newname("NOEND"));
- }
-